import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;

public class Downloader {
    public static String getHtml(String path) {
        Runtime runtime = Runtime.getRuntime();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(runtime.exec("curl " + path).getInputStream()));
            String line;
            StringBuilder b = new StringBuilder();
            while ((line = br.readLine()) != null) {
                b.append(line);
            }
            return b.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String getJs() {
        String html = getHtml("https://ssr.163.com/media/picture.html");
        String[] data_s = html.split("data_");
        return data_s[0].substring(data_s[0].lastIndexOf("\"") + 1) + "data_" + data_s[1].substring(0, data_s[1].indexOf("\""));
    }

    public static List<String> matchWithStartAndEnd(String content, String start, String end) {
        List<String> list = new LinkedList<>();
        String[] c;
        String d = content;
        while ((c = subUrl(d)) != null) {
            if (!c[0].contains("banner") && c[0].startsWith(start) && c[0].endsWith(end)) {
                list.add(c[0]);
            }
            d = c[1];
        }
        return list;
    }

    private static String[] subUrl(String content) {
        if (!content.contains("\"")) {
            return null;
        }
        String a = content.substring(content.indexOf("\"") + 1);
        if (!a.contains("\"")) {
            return null;
        }
        int index = a.indexOf("\"");
        String b = a.substring(0, index);
        return new String[]{b, a.substring(index + 1)};
    }

    public static void main(String[] args) {
        matchWithStartAndEnd(getHtml(getJs()), "https://ssr.res.netease.com", ".jpg").forEach(System.out::println);
    }
}
